package com.share.wechat.core.controller;

import com.share.wechat.core.entity.Category;
import com.share.wechat.core.service.CategoryService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 标题控制类
 * Created by er on 2017/12/18.
 */
@RestController
@RequestMapping("/core/detail/")
public class CategoryController {
    private final Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private CategoryService categoryService;

    @GetMapping("showCategory")
    public List<Category> showCategory(@RequestParam(value = "pid", required = false) int pid, @RequestParam(value = "level", required = false, defaultValue = "0") int level) {
        logger.debug("查询的pid=" + pid + ",查询的level为" + level + ".");

        List<Category> categoryList = categoryService.selectByLevelAndPid(level, pid);
        logger.debug("查询到的标题集合为" + categoryList);
        return categoryList;
    }


}
